<?php
class Services extends CI_Controller {
	
	public function __construct()
	{
		parent::__construct();
		$this->load->helper(array('url','authentication_helper'));
		$this->load->library('user_agent');
		$this->load->model(array('services_model','service_items_model'));
	}

	public function index()
	{
		$rs = $this->services_model->get_services();
		$data['services'] = $rs->result_array();
		if (empty($data['services']))
		{
		show_404();
		}
	
		$data['page_title'] = ucfirst('Services'); // Capitalize the first letter
		
		//replace to default file if not exists
		for ($i = 0; $i < count($data['services']); $i++) {
    		if (!isValidURL(base_url($data['services'][$i]['image_url']))) {
				$data['services'][$i]['image_url'] = 'resources/web/images/alt_logo_ourwork.png';
			}
		}
		
		$is_mobile = $this->agent->is_mobile();
		//$is_mobile = true; //uncomment for mobile version
	
		if (!$is_mobile) {
			$this->load->view('web/templates/header', $data);
			$this->load->view('web/services', $data);
			$this->load->view('web/templates/footer', $data);
		} else {
			$this->load->view('mobile/templates/header', $data);
			$this->load->view('mobile/services', $data);
			$this->load->view('mobile/templates/footer', $data);
		}
	}
	
	public function service_item($type)
	{
		$rs = $this->service_items_model->get_items($type);
		$data['items'] = $rs->result_array();
		if (empty($data['items']))
		{
		show_404();
		}
		
		$data['type'] = $type;
		
		//replace to default file if not exists
		for ($i = 0; $i < count($data['items']); $i++) {
    		if (!isValidURL(base_url($data['items'][$i]['image_url']))) {
				$data['items'][$i]['image_url'] = 'resources/web/images/alt_logo_casestudies1.png';
			}
		}
		
		if ($type == 'webvideo')
		{
			$type = 'Web Video';
		} else if ($type == 'trainingvideo')
		{
			$type = 'Training Video';
		} else if ($type == 'corporatevideo')
		{
			$type = 'Corporate Video';
		}
		$data['page_title'] = ucfirst($type); // Capitalize the first letter
		
		$is_mobile = $this->agent->is_mobile();
		//$is_mobile = true; //uncomment for mobile version
		if ($is_mobile) {
		$this->load->view('mobile/templates/header', $data);
		$this->load->view('mobile/service_item.php', $data);
		$this->load->view('mobile/templates/footer', $data);
		} else {
		$this->load->view('web/templates/header', $data);
		$this->load->view('web/service_item.php', $data);
		$this->load->view('web/templates/footer', $data);
		}
	}
}
